package com.chinanet.netelementmodel;

import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.pon.FH_GetFinalResult;
import com.chinanet.utils.pon.FH_SocketClient;
import com.chinanet.utils.pon.HW_Socket_AttrsIn;
import com.chinanet.utils.pon.OperationType;

import java.util.HashMap;
import java.util.Map;


/**
 * FH_Query_PON_OLT_under_the_number_of_alarmImp
 * 烽火PON网管-查询OLT PON下的告警数量
 * @author xuzhi
 *
 */
public class FH_Query_PON_OLT_under_the_number_of_alarmImp implements WorkInterFace {

	public String getName() {
		return "烽火PON网管-查询OLT PON下的告警数量";
	}

	public String getDesciption() {
		return "";
	}

	public int getVersion() {
		return 0;
	}

	public Attr[] getInAttrs() {
		Attr[] in = new Attr[3];
//		in[0] = new Attr("Port", "端口号", AttrType.TYPE_String, true);
		in[0] = new Attr("OLTID", "OLT的ID", AttrType.TYPE_String, true);
		in[1] = new Attr("PONID", "PON的ID，如：查询OLT设备上0框4槽1端口的光模块信息，PONID为NA-0-4-1", AttrType.TYPE_String, true);
		in[2] = new Attr("BEGINTIME", "开始时间,格式：yyyy-MM-dd HH-mm-ss", AttrType.TYPE_Date, true);
		return in;
	}

	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[6];
		out[0] = new Attr("flag", "操作是否成功，1：成功，0：失败", AttrType.TYPE_Int, true);
		out[1] = new Attr("Alarmfalg", "查询改pon下是否存在OLT PON口收无光，1：存在；0：不存在", AttrType.TYPE_Int, true);
		out[2] = new Attr("ONULoscount", "ONU电源掉电数量", AttrType.TYPE_Int, false);
		out[3] = new Attr("ONULosTimeflag", "ONU电源掉电时的时间正确度，1：正确；0：不正确", AttrType.TYPE_Int, false);
		out[4] = new Attr("ONUOutCount", "ONU离线数量", AttrType.TYPE_Int, false);
		out[5] = new Attr("log", "日志文件", AttrType.TYPE_String, true);
		return out;
	}

	public Map<String, Object> init(Map<String, Object> data) {
		Map<String, Object> inmap = new HashMap<String, Object>();
		Map<String, Object> intomap = new HashMap<String, Object>();
		Map<String, Object> outmap = new HashMap<String, Object>();
		FH_GetFinalResult result = new FH_GetFinalResult();
		String ip = "134.103.69.183";
		int port = 3337;
		System.out.println(port);
		FH_SocketClient fhclient = new FH_SocketClient(ip, port);
		HW_Socket_AttrsIn attrsin = new HW_Socket_AttrsIn();
		attrsin.setUsername("FH");
		attrsin.setPassword("FH123456");
		attrsin.setOLTID((String) data.get("OLTID"));
		attrsin.setPONID((String) data.get("PONID"));
		String BEGINTIME=(String) data.get("BEGINTIME");
		attrsin.setBEGINTIME(BEGINTIME);


		inmap = fhclient.init(attrsin,
				OperationType.TYPE_Query_PON_OLT_under_the_number_of_alarms);

		try {
			intomap = result.getPatterns_ALARM((String) inmap.get("ownlog"));
//			intomap = result.getPatterns_ALARM(Test.GetForkText("d:\\11.txt"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		boolean flag = (Boolean) inmap.get("flag");
//		boolean flag = true;
		if (flag) {
			outmap.put("flag", 1);
			outmap.put("log", inmap.get("log"));
//			outmap.put("log", Test.GetForkText("d:\\11.txt"));
		} else {
			outmap.put("flag", 0);
			outmap.put("log", inmap.get("log"));
//			outmap.put("log", Test.GetForkText("d:\\11.txt"));
		}
		outmap.putAll(intomap);

		return outmap;
	}

}
